package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigchun.seeland.R;

import java.util.List;

import bean.GoodsBean;
import util.GlideUtils;


public class GoodsFragmentAdapter extends BaseAdapter {



    private Context context;
    private LayoutInflater mInflater;
    List<GoodsBean.DataBean> mData;


    public GoodsFragmentAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    public GoodsFragmentAdapter(Context context, List<GoodsBean.DataBean> mData){
        this.context=context;
        this.mInflater = LayoutInflater.from(context);
        this.mData=mData;


    }
    public void setData(List<GoodsBean.DataBean> mData){
        this.mData=mData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {

            holder=new ViewHolder();

            convertView = mInflater.inflate(R.layout.item_goodfragment, null);

            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.tv_name.setText(mData.get(position).getStore_name());
//        Glide.with(context)
//                .load(mData.get(position).getImage())
//                .into(holder.img);

        if ("".equals(mData.get(position).getImage())){
            holder.img.setImageResource(R.mipmap.icon_wood_error);
        }else{
            GlideUtils.loadRoundCircleImage(context,mData.get(position).getImage()+"?x-oss-process=image/resize,w_420",holder.img);
        }
//        Glide.with(context).load(mData.get(position).getImage()).transform(new GlideRoundTransUtils(context, 10)).into(holder.img);

        /*Glide.with(context)
                .load(mData.get(position).getImage())
                .error(loadTransform)
                .transform(new CenterCrop(), new GlideRoundTransform(context))
                .placeholder(R.mipmap.ic_launcher)
                .crossFade()
                .override(DensityUtil.dp(context,60), DensityUtil.dp(context,60))
                .into(holder.img);*/
//        loadRoundImg(holder.img,mData.get(position).getImage(),R.drawable.app_color_bg,R.drawable.app_color_bg,10);

        return convertView;
    }

    public static class ViewHolder{

        TextView tv_name ;
        ImageView img ;



    }




}